package com.android.canvasproject.adapter;

import java.util.Arrays;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.android.canvasproject.R;
import com.android.canvasproject.enums.CanvasTypeEnum;

public class CanvasTypeSpinAdapter extends ArrayAdapter<CanvasTypeEnum> {

	private Context context;
	private List<CanvasTypeEnum> canvasType;

	public CanvasTypeSpinAdapter(Context ctx, int resource, CanvasTypeEnum[] objects) {
		super(ctx, resource, objects);

		context = ctx;
		canvasType = Arrays.asList(objects);
	}
	
	@Override
	public int getCount() {
		return canvasType.size();
	}
	
	@Override
	public CanvasTypeEnum getItem(int position) {
		return canvasType.get(position);
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView label = new TextView(context);
		label.setTextAppearance(getContext(), R.style.spinner_item);
		label.setPadding(4, 16, 4, 4);
		label.setText(canvasType.get(position).toString());
		
		return label;
	}
	
	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		TextView label = new TextView(context);
		label.setTextAppearance(getContext(), R.style.spinner_drop_down_item);
		label.setPadding(5, 10, 5, 10);
		label.setText(canvasType.get(position).toString());

		return label;
	}
}


















